/*
 * Created by 岱青海蓝信息系统(北京)有限公司 on 17-6-23 下午3:23
 * Copyright (c) 2017. All rights reserved.
 */

package com.example.dqhl.jdmetro.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.CountDownTimer;
import android.widget.TextView;

/**
 * Created by mac on 16/12/8.
 * 注册时发送验证码的倒计时工具类
 */
public class TimeCountRegisterUtil extends CountDownTimer {

    private Activity mActivity;
    private TextView tv;
    private int background_no;
    private int bacakground_click;

    public TimeCountRegisterUtil(Activity mActivity, long millisInFuture, long countDownInterval, TextView tv, int background_no,int bacakground_click) {
        super(millisInFuture, countDownInterval);
        this.mActivity = mActivity;
        this.tv = tv;
        this.background_no = background_no;
        this.bacakground_click = bacakground_click;
    }

    @SuppressLint("NewApi")
    @Override
    public void onTick(long millisUntilFinished) {
        String strSeconds = "剩余" + millisUntilFinished / 1000 + "秒";
        //设置不能点击
        tv.setClickable(false);
        //设置倒计时时间
        tv.setText(strSeconds);
        //设置按钮为灰色，这时是不能点击的
        tv.setBackgroundResource(background_no);
    }

    @SuppressLint("NewApi")
    @Override
    public void onFinish() {
        tv.setText("获取验证码");
        tv.setClickable(true);
        tv.setBackgroundResource(bacakground_click);
    }
}
